import React, {Component} from "react";
import {
	View,
	Text,
	Share,
	Button,
} from "react-native";

export default class ShareExam extends Component {
	constructor(props) {
		super(props);
		this.state = {
			result: ""
		}
	}
	_onPress() {
		Share.share({
			message: "用react-native来创建你的app"
		})
		.then(() => {
			if(result.action === share.shareAction) {
			if(result.activityType) {
				this.setState({result: 'shared with an activityType:' + result.activityType});
				console.log(this.state.result);
			}else {
				this.setState({result: 'shared'});
				console.log(this.state.result);
			}
		}else if(result.action === Share.dismissedAction) {
			this.setState({result: 'dismissed'});
			console.log(this.state.result);
		}
		})
		.catch((error) => this.setState({result: 'error:' + error.message}))
	}

	render() {
		return (
			<View> 
				<Button 
					title="分享"
					onPress={this._onPress}
				/>
				<Text>分享</Text>
			</View>
		);
	}
}